package com.snda.sc.auth;

import java.util.HashMap;
import java.util.Map;

import com.snda.sc.utils.Constants;
import com.snda.sc.utils.ToStringHelper;

public abstract class AbstractAuthResult implements AuthResult {

	protected int result;
	protected String plt;
	protected String cause;
	protected String appName;
	protected String code;
	protected String uid;
	protected String pt;
	protected String snsUid;
	protected String checkUrl;
	protected String appUrl;
	protected Map<String, Object> props = new HashMap<>();
	protected boolean testEnv;

	@Override
	public int getResult() {
		return result;
	}

	@Override
	public String getPlt() {
		return plt;
	}

	@Override
	public String getCause() {
		return cause;
	}

	@Override
	public String getAppName() {
		return appName;
	}

	@Override
	public String getCode() {
		return code;
	}

	@Override
	public String getUid() {
		return uid;
	}

	@Override
	public String getPt() {
		return pt;
	}

	@Override
	public String getSnsUid() {
		return snsUid;
	}

	@Override
	public String getCheckUrl() {
		return checkUrl;
	}

	@Override
	public String getAppUrl() {
		return appUrl;
	}

	@Override
	public Object getProperty(String name) {
		return props.get(name);
	}

	@Override
	public boolean isTestEnv() {
		return testEnv;
	}

	@Override
	public void setResult(int result) {
		this.result = result;
	}

	@Override
	public void setPlt(String plt) {
		this.plt = plt;
	}

	@Override
	public void setCause(String cause) {
		this.cause = cause;
	}

	@Override
	public void setAppName(String appName) {
		this.appName = appName;
	}

	@Override
	public void setCode(String code) {
		this.code = code;
	}

	@Override
	public void setUid(String uid) {
		this.uid = uid;
	}

	@Override
	public void setPt(String pt) {
		this.pt = pt;
	}

	@Override
	public void setSnsUid(String snsUid) {
		this.snsUid = snsUid;
	}

	@Override
	public void setCheckUrl(String checkUrl) {
		this.checkUrl = checkUrl;
	}

	@Override
	public void setAppUrl(String appUrl) {
		this.appUrl = appUrl;
	}

	@Override
	public void setProperty(String name, Object value) {
		props.put(name, value);
	}

	@Override
	public void setTestEnv(boolean testEnv) {
		this.testEnv = testEnv;
	}

	protected Map<String, Object> mergeProp() {
		Map<String, Object> map = new HashMap<>();
		map.put("result", result);
		if (result != Constants.ResultCode.AUTH_OK) {
			map.put("cause", cause);
			return map;
		}

		map.putAll(props);
		map.put("plt", plt);
		map.put("appname", appName);
		map.put("code", code);
		map.put("uid", uid);
		map.put("pt", pt);
		map.put("snsUid", snsUid);
		map.put("checkURL", checkUrl);
		map.put("appUrl", appUrl);
		return map;
	}

	@Override
	public String toString() {

		ToStringHelper helper = new ToStringHelper(getClass());
		helper.append("result", result);
		if (result != Constants.ResultCode.AUTH_OK) {
			return helper.append("cause", cause).toString();
		}

		helper.appendAll(props);
		helper.append("plt", plt);
		helper.append("appname", appName);
		helper.append("code", code);
		helper.append("uid", uid);
		helper.append("pt", pt);
		helper.append("snsUid", snsUid);
		helper.append("checkURL", checkUrl);
		helper.append("appUrl", appUrl);
		return helper.toString();
	}
}
